3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
This section describes the routines that QuickDraw 3D provides to register and unregister custom object classes.
When a plug-in custom type is registered, its type parameter is allocated dynamically. Types are registered with Q3XObjectHierarchy_RegisterClass or Q3XElementClass_Register , or with the Q3XAttributeClass_Register routine as described in "Adding Application-Defined Attribute and Element Types" . In the case of Q3XObjectHierarchy_RegisterClass , the second parameter is the address of an object type-- TQ3ObjectType , TQ3ElementType or TQ3AttributeType , depending on the call used for registration.
When your custom class uses a shared library, you should coordinate class registration with library registration. For more information, including sample code, see "Registering a Shared Library" .
You can use the Q3XObjectHierarchy_RegisterClass routine to register a class in the QuickDraw 3D hierarchy.
TQ3XObjectClass Q3XObjectHierarchy_RegisterClass(
TQ3ObjectType parentType,
TQ3ObjectType *objectType,
char *objectName,
TQ3MetaHandler metaHandler,
TQ3MetaHandler virtualMetaHandler,
unsigned long methodsSize,
unsigned long instanceSize);
The Q3XObjectHierarchy_RegisterClass routine registers the custom class detailed by its parameters. The object type is assigned at run time and returned to you in the objectType parameter. Often it is a good idea to store this type locally in a static variable, since it is used by many object system routines.
The Q3XObjectHierarchy_RegisterClass routine returns NULL if the class could not be registered.
You should generally call Q3XObjectHierarchy_RegisterClass only in a function that has been registered by the Q3XSharedLibrary_Register call. Register the existence of this routine instead of calling it directly from a shared library registration routine.
The following is an example of a registration function, taken from the plug-in renderer sample in the QuickDraw 3D SDK. In this example the return value of the Q3XObjectHierarchy_RegisterClass function is stored in the global variable SRgRendererClass . To make this variable readily available to other code, it is declared static to the file in which the routine is implemented.
TQ3Status SR_Register(
void)
{
/* Create/register the class */
SRgRendererClass =
Q3XObjectHierarchy_RegisterClass(
kQ3SharedTypeRenderer,
&SRgClassType,
"SampleRenderer",
SR_MetaHandler,
NULL,
0,
sizeof(TSRPrivate));
/* Make sure it worked */
if (SRgRendererClass == NULL) {
return (kQ3Failure);
}
return (kQ3Success);
}
You can use the Q3XObjectHierarchy_UnregisterClass function to remove a custom object class registered with Q3XObjectHierarchy_RegisterClass.
TQ3Status Q3XObjectHierarchy_UnregisterClass (
TQX3ObjectClass objectClass);
The Q3XObjectHierarchy_UnregisterClass function unregisters the custom object class specified by the objectClass parameter.
You should dispose of all instances of the custom object class you want to unregister before calling Q3XObjectHierarchy_UnregisterClass. If this is not done, Q3XObjectHierarchy_UnregisterClass returns kQ3Failure and the class remains registered.
You can also call Q3XObjectHierarchy_UnregisterClass to unregister a custom attribute type previously registered by the function Q3AttributeClass_Register .
You can use the Q3ElementClass_Register function to register an application-defined element class.
TQ3ObjectClass Q3ElementClass_Register (
TQ3ElementType elementType,
const char *name,
unsigned long sizeOfElement,
TQ3MetaHandler metaHandler);
The Q3ElementClass_Register function returns, as its function result, an object class reference for a new custom element type having a type specified by the elementType parameter and a name specified by the name parameter. The metaHandler parameter is a pointer to the metahandler for your custom element type. See "Defining an Object Metahandler" for information on writing a metahandler. If Q3ElementClass_Register cannot create a new element type, it returns the value NULL .
The name parameter should be a pointer to null-terminated C string that contains your (or your company's) name and the name of the type of element you are defining. Use the colon character (:) to delimit fields within this string. The string should not contain any spaces or punctuation other than the colon character, and it cannot end with a colon. Here are some examples of valid creator names:
"MyCompany:SurfDraw:Wavelength"
"MyCompany:SurfWorks:VRModule:WaterTemperature"
The sizeOfElement parameter specifies the fixed size of the data associated with your custom element type. If you wish to associate dynamically sized data with your element type, put a pointer to a dynamically sized block of data into the set and have your handler's copy method duplicate the data. (In this case, you would set the sizeOfElement parameter to sizeof(Ptr) .) You also need to have your handler's dispose method deallocate any dynamically sized blocks.
You can use the Q3ElementType_GetElementSize function to get the size of an application-defined element type.
TQ3Status Q3ElementType_GetElementSize (
TQ3ElementType elementType,
unsigned long *sizeOfElement);
Previous | QD3D Book | Overview | Chapter Contents | Next |